<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标移动盒子</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            position: absolute;
            left: 0;
            top: 0;
            background-color: #475388;
        }
    </style>
</head>

<body>
    <div id="div"></div>
    <script>
        let div = document.getElementById("div");

        document.onmousemove = (e) => {
            let event = e || window.event;
            div.style.left = event.clientX - div.clientWidth / 2 + "px";
            div.style.top = event.clientY - 50 + "px";
        }
    </script>
</body>

</html>